function WordsMerge(words) {

    let res = ''; //最终结果

    //遍历字符列表
    words.forEach(e => {

        let strs = e.split('');
        let pres = res.split(''); //这是前一个字符串数组
        //判断谁长度大,然后遍历判断
        let m = strs.length;
        let n = pres.length;
        let c = m < n ? m : n; //c表示最小的
        let count = 0; //表示前后两项字符数组要切割的数
        // console.log('进入', res, e, n);
        for (let i = 0; i < c; i++) {
            // console.log("循环中", pres[n - i - 1], strs[i]);
            if (pres[n - i - 1] == strs[i]) {
                count++;
            }
        }
        strs.splice(0, count);
        pres.splice(n - count, count); //切割数组
        // console.log("切割数:", pres, strs);
        res = pres.concat(strs).join('');
    });
    return res;
}

console.log(WordsMerge(["aab", "bac", "ccd"]));

module.exports = {
    WordsMerge: WordsMerge
};